using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using mvLibrary;

namespace fenk.Admin.Bancos
{
    public partial class ControlMBancos : mvLibrary.BaseForm
    {
        private const int CHEQUES_INDEX = 0;
        private const int DEBITOS_INDEX = 1;
        private const int DEPOSITOS_INDEX = 2;

        public ControlMBancos()
        {
            InitializeComponent();
        }

        protected override void OnCancelItem()
        {
            radCheques.Checked = true;
            this.cbTipoMovimiento.SelectedIndex = CHEQUES_INDEX;
            radDebitos.Checked = false;
            radDepositos.Checked = false;
        }

        private void radCheques_CheckedChanged(object sender, EventArgs e)
        {
            this.cbTipoMovimiento.SelectedIndex = CHEQUES_INDEX;
            Refactor(CHEQUES_INDEX);
        }

        private void radDebitos_CheckedChanged(object sender, EventArgs e)
        {
            this.cbTipoMovimiento.SelectedIndex = DEBITOS_INDEX;
            Refactor(DEBITOS_INDEX);
        }

        private void radDepositos_CheckedChanged(object sender, EventArgs e)
        {
            this.cbTipoMovimiento.SelectedIndex = DEPOSITOS_INDEX;
            Refactor(DEPOSITOS_INDEX);
        }

        private void Refactor(int selectedIndex)
        {
            BaseForm formulario = FindForm() as BaseForm;
            if (formulario == null)
            {
                return;
            }
            if (!Parent.Enabled)
            {
                return;// Evita validar el control cuando ItemSave() o ItemCancel() limpian el formulario
            }
            formulario.SetErrorProvider(this, "");
            if (selectedIndex == -1)
            {
                formulario.SetErrorProvider(this, "Seleccione un item de la lista");
                return;
            }

            formulario.SetItemId();

        }

    }
}

